import { defineStore } from 'pinia';
import { ref } from 'vue';
import type { Consult, ConsultIllness } from '@/types/consult';

// 导出获取 consult store 的方法
export const useConsultStore = defineStore(
  'cp-consult',
  () => {
    // 定义管理的数据，我们目前知道是这个将来这个对象里会存很多数据
    const consult = ref<Consult>({});
    // 以及我们还会定义若干修改这些数据的方法
    // TODO 修改数据的方法

    // 设置问诊的类型
    const setType = (type: 1 | 2 | 3) => {
      consult.value.type = type;
    };
    // 设置极速问诊类型:0 普通 1 三甲
    const setIllnessType = (type: 0 | 1) => {
      consult.value.illnessType = type;
    };
    // 设置选择的科室
    const setDept = (id: string) => {
      consult.value.depId = id;
    };
    // 设置病情描述
    const setIllness = (illness: ConsultIllness) => {
      consult.value.illnessDesc = illness.illnessDesc;
      consult.value.illnessTime = illness.illnessTime;
      consult.value.consultFlag = illness.consultFlag;
      consult.value.pictures = illness.pictures;
    };
    // 设置患者id
    const setPatient = (patientId: string) => {
      consult.value.patientId = patientId;
    };
    // 设置优惠券id
    const setCoupon = (id: string) => {
      consult.value.couponId = id;
    };
    // 清空就诊信息
    const clear = () => {
      consult.value = {};
    };
    return { consult, setType, setIllnessType, setDept, setIllness, setPatient, setCoupon, clear };
  },
  { persist: true }
);
